package morenoapp.components.common.table.column;

import javax.swing.table.TableColumn;
import morenoapp.components.common.AbstractCustomColumnsMorenoTableModel;

/**
 *
 * @author dmitry.mamonov
 */
public class MorenoCustomTableColumnModel extends ImmovableTableColumnModel {
    private AbstractCustomColumnsMorenoTableModel tableModel;

    public MorenoCustomTableColumnModel(AbstractCustomColumnsMorenoTableModel aTableModel) {
        super();
        if (aTableModel == null) {
            throw new IllegalArgumentException("Model must not be null"); //NOI18N
        }
        this.tableModel = aTableModel;
    }

    @Override
    public void addColumn(TableColumn aColumn) {
        ColumnMeta columnMeta = tableModel.getColumnMeta(aColumn.getModelIndex());
        aColumn.setMaxWidth(columnMeta.getMaximumWidth());
        aColumn.setMinWidth(columnMeta.getMinimumWidth());
        aColumn.setPreferredWidth(columnMeta.getPrefferedWidth());
        if (columnMeta.getTableCellRenderer() != null) {
            aColumn.setCellRenderer(columnMeta.getTableCellRenderer());
        }
        super.addColumn(aColumn);
    }
}
